/*
* Copyright (C) Microsoft. All rights reserved.  
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not 
* use this file except in compliance with the License.  You may obtain a copy 
* of the License at http://www.apache.org/licenses/LICENSE-2.0  
* 
* THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
* WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
* MERCHANTABLITY OR NON-INFRINGEMENT. 
*
* See the Apache License, Version 2.0 for specific language governing 
* permissions and limitations under the License.
*
*/
#pragma once

#include <journal/models/interfaces.h>
#include <journal/models/internal_interfaces.h>

namespace journal { namespace model {

namespace b = baja;
namespace s = baja::storage;

class ink_surface_model_factory : public iink_surface_model_factory
{
public:
    ink_surface_model_factory(std::shared_ptr<s::iengine> dbEngine);
    static std::shared_ptr<iink_surface_model_factory> create(std::shared_ptr<s::iengine> dbEngine);

    // iink_surface_model_factory
    void getPersistedInkSurfaceIds(
        b::uint32 pageId,
        std::vector<b::uint32>& ids
        );

    void removeFromDB(
            const b::uint32& pageId
            );

    std::shared_ptr<iink_surface_model> createInkSurface(
        const std::shared_ptr<ipage_model>& parent
        );

    std::shared_ptr<iink_surface_model> recreateInkSurface(
        const std::shared_ptr<ipage_model>& parent,
        const b::uint32 inkSurfaceId
        );

private:
    static b::uint32 _typeToken;
    b::uint32 _nextId;
    static const b::uint32 _firstLoadPass;
    std::shared_ptr<s::iengine> _dbEngine;
    std::shared_ptr<journal::model::db::iink_surface_table> _inkSurfaceTable;
};

std::shared_ptr<iink_surface_model_factory> createInkSurfaceModelFactory(std::shared_ptr<s::iengine> dbEngine);

}} // namespace journal::model